package com.yunji.storage.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.storage.bo.StorageRecordsListQueryBO;
import com.yunji.storage.dao.IStorageRecordsDao;
import com.yunji.storage.domain.StorageRecordsDO;
import com.yunji.storage.mapper.StorageRecordsMapper;
import org.springframework.stereotype.Repository;

import java.util.Arrays;
import java.util.List;

@Repository
public class StorageRecordsDaoImpl extends BaseDaoImpl<StorageRecordsMapper, StorageRecordsDO> implements IStorageRecordsDao {
    @Override
    public List<StorageRecordsDO> search(StorageRecordsListQueryBO bo) {
        return list(new LambdaQueryWrapper<StorageRecordsDO>()
                .eq(BeanUtils.isNotNull(bo.getTicketId()), StorageRecordsDO::getTicketId, bo.getTicketId())
                .eq(BeanUtils.isNotNull(bo.getTicketCode()), StorageRecordsDO::getTicketCode, bo.getTicketCode()));
    }

    @Override
    public boolean deleteByTicketIds(Long... ticketIds) {
        return remove(new LambdaQueryWrapper<StorageRecordsDO>()
                .in(StorageRecordsDO::getTicketId, Arrays.asList(ticketIds)));
    }
}
